import React from 'react';
import { observer } from 'mobx-react';
import { Actions } from "react-native-router-flux";
import Form, {validate} from '../../../components/Former';
import Button from '../../../components/Button';
import Spin from '../../../components/spin';
import user from '../../../common/models/user';

@observer
class MyForm extends React.Component {
  _validate = () => {
    validate((err, val) => {
      if (!err) {
        user.setInstitutionId(val.insuranceOrgId).then(institutionId => {
          if (institutionId) {
            Actions.inputInstitutionInfo({ institutionId });
          }
        });
      }
    });
  };

  fields = [
    {
      title: '第一步：输入机构编码并查询机构',
      type: 'Title'
    },
    {
      label: '机构编码',
      placeholder: '请输入机构编码',
      type: 'TextInput',
      key: 'insuranceOrgId',
      rules: [{ require: true }],
    },
  ]
  render() {
    return (
      <Spin visible={this.props.user.pending}>
        <Form
          fields={this.fields}
          bottom={
            <Button
              onPress={this._validate}
              type="primary"
              title="提交机构编码"
            />
          }
        />
      </Spin>
    );
  }
}

export default MyForm;
